# -*- coding: UTF-8 -*-
'''
Created on 2011-2-01

@author: sumory
'''
import os

def uic(path):
    path=path.encode('gbk')
    print('要生成文件的目录是：'+path.decode('gbk'))
    count=[0,0]
    try:
        for root, dirs, files in os.walk(path):
            for file in files:
                file_path=os.path.join(root,file)
                
                if file_path.endswith('.ui'):
                    print('+'+os.path.join(root,'ui_'+file.rsplit('.', 1)[0]+'.py').decode('gbk'))
                    os.system('pyuic4 -o %s %s' % (os.path.join(root,'ui_'+file.rsplit('.', 1)[0]+'.py'), file_path))
                    count[0]=count[0]+1
                elif file_path.endswith('.qrc'):
                    print(':'+os.path.join(root,file.rsplit('.', 1)[0]+'_rc.py').decode('gbk'))
                    print(':'+file_path.decode('gbk'))
                    os.system('pyrcc4 -o %s %s' % (os.path.join(root,file.rsplit('.', 1)[0]+'_rc.py'), file_path))
                    count[1]=count[1]+1
            if(True):#不递归子目录
                break
        return ['ok','转换ui文件'+str(count[0])+"个；"+'转换qrc文件'+str(count[1])+"个。"]
    except IOError as e:
        print('发生异常')
        print(e)
        return ['exception',count]

#uic('D:\\QtUi'.decode('utf-8'))
